﻿using LJSheng.Common;
using LJSheng.Data;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace LJSheng.Web
{
    public partial class denglu : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Login_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.txtcode.Value)) { Common.JS.Alert("请输入验证码。", this); return; }
            if (string.IsNullOrEmpty(this.txtusername.Value.Trim())) { Common.JS.Alert("请输入用户名。", this); return; }
            if (string.IsNullOrEmpty(this.txtpassword.Value.Trim())) { Common.JS.Alert("请输入密码。", this); return; }
            if (!Common.LCookie.GetCookie("CheckCode").Equals(this.txtcode.Value.Trim())) { Common.JS.Alert("验证码错误。", this); return; }
            using (EFDB db = new EFDB())
            {
                string account = txtusername.Value.Trim();
                string pwd = Common.MD5.GetMD5ljsheng(txtpassword.Value.Trim());
                var b = db.LUser.Where(l => l.account == account && l.pwd == pwd).FirstOrDefault();
                if (b != null)
                {
                    Common.LCookie.DelCookie("CheckCode");
                    Common.LCookie.AddCookie("linjiansheng", DESRSA.DESEnljsheng(JsonConvert.SerializeObject(new
                    {
                        b.gid,
                        b.account,
                        b.loginid,
                        b.qx
                    })), 0);
                    Response.Redirect("/shop/houtai");
                }
                else
                {
                    Common.JS.Alert("您输入的用户或密码错误。", this);
                }
            }
        }
    }
}